window.device = {};

let ua = navigator.userAgent.toLocaleLowerCase();
device.isWX = ua.match(/micromessenger/i) == 'micromessenger';
device.isIOS = ua.match(/iphone os/i) == 'iphone os'
device.isAndroid = ua.match(/android/i) == 'android';

window.NativeApp = {
    popCurrentVCFunc(info) { //原生页面退出/返回上一页【从右往左】
        info = info || '';
        if (device.isIOS) {
            return window.webkit.messageHandlers.jssdk.postMessage({ "func":"popCurrentVCFunc","param":info});
        } else {
            return jssdk.popCurrentVCFunc(info);
        }
    },
    getUserInfoFunc(info) { //获取用户信息
        info = info || '';
        if (device.isIOS) {
            return window.webkit.messageHandlers.jssdk.postMessage({ "func":"getUserInfoFunc","param":info});
        } else {
            return jssdk.getUserInfoFunc(info);
        }
    },
    loadGoodsDetailFunc(info) { //跳转商品详情
        info = info || '';
        if (device.isIOS) {
            window.webkit.messageHandlers.jssdk.postMessage({ "func":"loadGoodsDetailFunc","param":info});
        } else {
            jssdk.loadGoodsDetailFunc(info);
        }
    },
    loadHomePageFunc(info) { //跳转首页
        info = info || '';
        if (device.isIOS) {
            window.webkit.messageHandlers.jssdk.postMessage({ "func":"loadHomePageFunc","param":info});
        } else {
            jssdk.loadHomePageFunc(info);
        }
    },
    loadCategoryPageFunc(info) { //跳转分类页
        info = info || '';
        if (device.isIOS) {
            window.webkit.messageHandlers.jssdk.postMessage({ "func":"loadCategoryPageFunc","param":info});
        } else {
            jssdk.loadCategoryPageFunc(info);
        }
    },
    showShareViewFunc(info) { //显示分享面板
        info = info || '';
        if (device.isIOS) {
            window.webkit.messageHandlers.jssdk.postMessage({ "func":"showShareViewFunc","param":info});
        } else {
            jssdk.showShareViewFunc(info);
        }
    },
    
    loadPayViewFunc() {
        info = info || '';
        if (device.isIOS) {
            window.webkit.messageHandlers.jssdk.postMessage({ "func":"loadPayViewFunc","param":info});
        } else {
            jssdk.showShareViewFunc(info);
        }
    }
}
